package com.gitee.wsl.unit.angle.ext

import com.gitee.wsl.mathematics.interpolator.Percent
import com.gitee.wsl.unit.angle.AngleUnit
import com.gitee.wsl.unit.angle.AngleUnit.Companion.fromDegrees
import com.gitee.wsl.unit.angle.AngleUnit.Companion.fromRadians
import com.gitee.wsl.mathematics.interpolator.times

infix operator fun AngleUnit.plus(other: AngleUnit): AngleUnit = AngleUnit.Degrees(toBase() + other.toBase())
infix operator fun AngleUnit.minus(other: AngleUnit): AngleUnit = AngleUnit.Degrees(toBase() - other.toBase())
infix operator fun AngleUnit.times(other:Number): AngleUnit = AngleUnit.Degrees(toBase() * other.toDouble())
infix operator fun AngleUnit.div(other:Number): AngleUnit = AngleUnit.Degrees(toBase() / other.toDouble())
infix operator fun AngleUnit.times(percent: Percent): AngleUnit = AngleUnit.Degrees(toBase() * percent)
operator fun AngleUnit.unaryMinus(): AngleUnit = AngleUnit.Degrees(-toBase())

infix operator fun Number.times(other: AngleUnit): AngleUnit = other * this

fun AngleUnit.plusDegrees(degrees: Double) = fromDegrees(this.degrees + degrees)
fun AngleUnit.plusRadians(radians: Double) = fromRadians(this.radian + radians)

fun AngleUnit.minusDegrees(degrees: Double) = fromDegrees(this.degrees - degrees)
fun AngleUnit.minusRadians(radians: Double) = fromRadians(this.radian - radians)

/**
 * Multiplies this angle by another angle.
 * This method is commutative, so `a.multiply(b)` and `b.multiply(a)` are equivalent.
 * This angle remains unchanged. The result is returned as a new angle.
 *
 * @param angle the angle by which to multiply.
 *
 * @return a new angle whose size equals this angle's size multiplied by angle's size.
 */
operator fun AngleUnit.times(angle: AngleUnit) = this * angle.degrees

/**
 * Divides this angle by another angle.
 * This angle remains unchanged. The result is returned as a new angle.
 *
 * @param angle the angle by which to divide.
 *
 * @return this angle's degrees divided by angle's degrees.
 */
operator fun AngleUnit.div(angle: AngleUnit) = this / angle.degrees